define([
    'jquery',
    'underscore',
    'backbone',
    'module/unit/models/UnitModel',
    'text!module/unit/templates/edit.html'

], function($, _, Backbone, UnitModel, edit) {
    var EditView = Backbone.View.extend({
        el: $("#main-list"),
        events: {"click #edit_action": "edit_action", },
        render: function() {
            var data = {}


            //var template = _.template(edit, data);
            //this.$el.append(template);
            $("#main-list").html(edit);
            var unit = new UnitModel({id: this.options.id});
            unit.fetch({
                success: function(jsonr) {
                    jsonr = jsonr.toJSON();
                    $("#id").val(jsonr.id);
                    $("#name").val(jsonr.name);
                    $("#code").val(jsonr.code);
                }
            });
        },
        edit_action: function() {           
            var unit = new UnitModel();
            var unitDetails = {
                id: $("#id").val(),
                name: $("#name").val(),
                code : $("#code").val()
            };
            unit.save(unitDetails, {
                success: function(data) {
                    window.locate.hash = "unit";
                }
            });
        }
    });
    return EditView;
});


